<?php
/**
 * Created by PhpStorm.
 * User: cjm
 * Date: 2018/10/7
 * Time: 0:11
 */

namespace App\Transformers;
use App\User;

use League\Fractal\TransformerAbstract;

class UsersTransformer extends TransformerAbstract
{
    protected $type;

    public function __construct($type){
        $this->type = $type;
    }

    public function transform(User $user){
        if ($this->type) {
            return [
                'id' => $user->id,
                'name' => $user->name,
                'email' => $user->email,
                'avatar' => $user->avatar,
                'introduction' => $user->introduction,
                'bound_phone' => $user->phone ? true : false,
                'bound_wechat' => ($user->weixin_unionid || $user->weixin_openid) ? true : false,
                // 'last_actived_at' => $user->last_actived_at->toDateTimeString(),
                'p_money' => $user->p_money,
                'z_money' => $user->p_money,
                'g_money' => $user->p_money,
                'created_at' => $user->created_at->toDateTimeString(),
                'updated_at' => $user->updated_at->toDateTimeString(),
            ];
        }else{
                return[
                    'id' => $user->id,
                    'name' => $user->name,
                    'avatar' => $user->avatar,
                    'p_money' => $user->p_money,
                    'z_money' => $user->p_money,
                    'g_money' => $user->p_money,
                ];
        }

    }

}